<template>
  <div>
    <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" size="small"
             style="width: 90%;">
      <el-form-item label="名称" prop="name">
        <el-input type="text" v-model="ruleForm.name" autocomplete="off">
        </el-input>
        <span v-show="showExits" style="text-align:left;color:red;position: absolute;width: 20rem;margin-left: -24rem;margin-top: 2rem">
          {{ showExits }}
        </span>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    let validateName = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入名称'));
        return;
      }
      callback();
    };
    return {
      showExits: false,
      ruleForm: {
        name: ''
      },
      rules: {
        name: [
          {validator: validateName, trigger: 'blur'}
        ]
      }
    };
  },
  methods: {
    clear() {
      this.ruleForm.name = null;
      this.showExits = false;
    },
    exitsShow(msg) {
      this.showExits = msg;
    }
  },
  watch: {
    ruleForm: {
      deep: true,
      handler(o, n) {
        if (n && n.name && n.name !== '') {
          this.$emit('valueOk', {status: true, value: n});
          return;
        }
        this.$emit('valueOk', {status: false, value: n});
      }
    }
  }
}
</script>

<style scoped>

</style>
